<%@ include file="../../commons/common.jsp" %>

<form id="userListForm" action="user.htm">

	<c:set var="formFilter" value="${sessionScope.userFilter}" />
	
	<table class="body-table" cellpadding="0" cellspacing="0">	
		<tr>
			<td class="title">MenuItem</td>
		</tr>
		<tr>
			<td class="functions">
			<ul>		
				<li onclick="frm.newItem('new.htm');">Nuovo</li>				
				<li onclick="frm.deleteItems('list.htm');">Elimina</li>
				<li onclick="frm.refresh();">Aggiorna</li>	
			</ul>
			</td>
		</tr>
		
		<tr>
			<td class="detail">
				<input type="text" name="filterValue" value="${formFilter.filterValue}">&nbsp;
				<select name="filterName">
					<option value=""> -- </option>
					<option value="DBUser.username">username</option>
				</select>
				&nbsp;
				<input type="image" src="${searchIcon}" style="vertical-align:bottom;" alt="Cerca" onclick="frm.simpleFilter();" />
				<input type="image" src="${cancelIcon}" style="vertical-align:bottom;" alt="Cancella filtro" onclick="frm.resetFilter();"/>
			</td>
		</tr>
	</table>
	
	<acanto:dataset id="listaUserDs" stateful="true" query="from DBUser DBUser" orderBy="DBUser.username" resultsPerPage="20">
		<acanto:datasetFilter>
			<c:if test="${not empty formFilter}">
				<acanto:filterCondition	fieldName="${formFilter.filterName}" value="${formFilter.filterValue}" operator="startsWith" />
			</c:if>
		</acanto:datasetFilter>
	</acanto:dataset>	
	
	<acanto:datatable dataset="${listaUserDs}" htmlClass="data" cellpadding="1" cellspacing="1" 
					defaultAscImg="${ascIcon}" defaultDescImg="${descIcon}"
					rendered="${listaUserDs.availableRows > 0}">
		<tr>
			<th style="text-align:left; width: 20px;">N.</th>
			<acanto:header htmlClass="checkbox">
				<input type="checkbox" onclick="checksAll('deleteIds', this);" />
			</acanto:header>
			<acanto:header orderBy="DBUser.enabled" value="enable" />
			<acanto:header orderBy="DBUser.username" style="width: 40px;">username</acanto:header>
			<acanto:header orderBy="DBUser.email" style="width: 40px;">email</acanto:header>
		</tr>
		<acanto:row style="cursor:pointer;">
			<td style="text-align:left;">${absoluteRowNumber}.</td>
			
			<td class="checkbox">
				<input type="checkbox" name="deleteIds" value="${row.username}">
			</td>
			<td onclick="frm.edit('editItem.htm','itemId=${row.username}' );">
		    	<img src="${ row.enabled ? enableIcon : disableIcon}" />
			</td>
			<td onclick="frm.edit('editItem.htm','itemId=${row.username}');">
				${row.username}				
			</td>
			<td onclick="frm.edit('editItem.htm','itemId=${row.username}');">
				${row.email}				
			</td>
		</acanto:row>
	</acanto:datatable>
	
	<c:set var="ds" scope="request" value="${listaUserDs}" />
	
	<%@ include file="../../commons/paging.jsp" %>

</form>

<script type="text/javascript">
<!--
var frm = new AcantoForm('userListForm', false , stripesCallback);

function stripesCallback(stripesEvent, stripesForm)
{
	if(stripesEvent == stripesForm.DELETE)	
	{
		countChecked = countCheckedCheckbox('deleteIds');
		
		if( countChecked > 0)
		{
			return confirm( countChecked == 1 ? 'Vuoi cancellare l\'anagrafica selezionata?': 
			                                    'Vuoi cancellare le anagrafiche selezionate?');					
		}
		else
		{
			var warn = new MessageBundle('msgContainer', 'warnings');
			warn.setMessage('Selezionare almeno un elemento !');
			warn.setMessageHeader('Attenzione!');
			warn.displayMessages();

			return false;
		}
	}
	else
		return true;
}
//-->
</script>
